#include <bits/stdc++.h>
#define int long long
using namespace std;
void file(string x)
{
    freopen((x + ".in").c_str(), "r", stdin);
    freopen((x + ".out").c_str(), "w", stdout);
}
signed main()
{
    file("kte");
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    vector<int> vec;
    while (T--)
    {
        int n;
        cin >> n;
        auto tmp = find(vec.begin(), vec.end(), n);
        if (tmp != vec.end()) vec.erase(tmp);
        else vec.emplace_back(n);
        sort(vec.begin(), vec.end());
        if (vec.size() <= 1)
        {
            cout << "0\n";
            continue;
        }
        int sum1 = 0, sum2 = 0;
        for (int i = 0; i < vec.size() - 1; i++)
            sum1 += vec[i], sum2 += vec[vec.size() - i - 1];
        pair<int, int> nowp(sum1, sum2 - 1);
        int now = vec.size() - 1, ans = 0;
        while (--now)
        {
            sum1 -= vec[now], sum2 -= vec[vec.size() - now - 1];
            if (sum2 - 1 < nowp.first)
            {
                ans += nowp.second - nowp.first + 1;
                nowp = make_pair(sum1, sum2 - 1);
            }
            else nowp.first = sum1;
        }
        ans += nowp.second - nowp.first + 1;
        cout << ans << '\n';
    }
    return 0;
}